<?php
/* @var $this yii\web\View */
use yii\helpers\Html;
use yii\helpers\Url;
use yii\widgets\ActiveForm;
$this->title = '重设密码';
$this->params['breadcrumbs'][] = $this->title;
?>
<br>
<section class="container">
<div class="card">
  <a href="<?=Url::toRoute('site/login')?>" style='float:right;'><i class="fa fa-angle-left"></i> 返回登录页面</a>
  <h3 class="login-head"><i class="fa fa-lg fa-fw fa-key"></i> 重设密码</h3>

  <div class='card-body'>
  <?php $form = ActiveForm::begin(); ?>

  <?php
    if(isset($tip)&&$tip===true){
      if($model->hasErrors()){
  ?>
        <div class="alert alert-danger" role="alert">
          <?php
              foreach($model->getErrors("") as $key=>$value){
                echo $value."<br>";
              }
          ?>
        </div>
  <?php
      }else{
  ?>
        <div class="alert alert-success" role="alert">重设密码成功！</div>
  <?php
      }
    }
  ?>
      <?=Html::activeHiddenInput($model,'name');?>

      <div class="form-group">
        <?=$form->field($model, 'phone',['enableAjaxValidation'=>true])->label('请输入注册时使用的手机号码')?>
      </div>
      <div class="form-group">
        <?=$form->field($model, 'sms',['enableAjaxValidation'=>true])->label('短信验证码&nbsp;<button id="getsmsbtn" type="button" onclick="sendsms();">获取手机短信验证码</button>')?>
      </div>
      <div class="form-group">
        <?=$form->field($model, 'pw')->passwordInput()->label('重新设置密码')->hint("请记住您的新密码，用于下次登录使用，不能透露予他人")?>
      </div>

      <div class="form-group">
          <?= Html::submitButton('<i class="fa fa-fw fa-lg fa-check-circle"></i>提交', ['class' => 'btn btn-warning']) ?>
      </div>


  <?php ActiveForm::end(); ?>
  </div>
</div>
<!-- footer content -->
<footer class="footer">
  <div class="container" style="text-align:center;color:white;">
    <br>
    Copyright © 2017 <?=$this->context->sysConfig->site_name?> 版权所有
    &nbsp;&nbsp;<span>|</span>
    &nbsp;&nbsp;<?=$this->context->sysConfig->site_reg_id?>
    &nbsp;&nbsp;<span>|</span>
    &nbsp;&nbsp;<a href="http://<?=$this->context->sysConfig->site_addr?>" target="_blank">关于<?=$this->context->sysConfig->site_name?></a>
  </div>
</footer>
<!-- /footer content -->
</section>

<?php $this->beginBlock('getsmscode') ?>
var countdown=60;
function settime() {
   if (countdown == 0) {
        $('#getsmsbtn').removeAttr("disabled");
        $('#getsmsbtn').text("获取手机短信验证码");
        countdown = 60;
        return;
    } else {
        $('#getsmsbtn').attr("disabled", true);
        $('#getsmsbtn').text("重新获取验证码(" + countdown + ")");
        countdown--;
    }
  setTimeout(function() { settime() } ,1000)
}

function sendsms(){
    var phoneinvalid=$("#forgetpwform-phone").attr("aria-invalid");
    if(phoneinvalid==="true"){
      alert("请先输入正确的手机号码");
      return;
    }else{
      var phone=$("#forgetpwform-phone").val();
      if(phone.length>0){
        settime();
        var csrfToken = $('meta[name="csrf-token"]').attr("content");
        $.ajax({
          url:"<?=Url::toRoute('site/sendsms')?>",
          type:"get",
          datatype:"json",
          cache:false,
          data:{phone:phone,_csrf:csrfToken},
          success:function(data){
          console.log(data);
          },
          error:function(jqXHR,textStatus,errorThrown){
            console.log(jqXHR);
            console.log(textStatus);
            console.log(errorThrown);
          }
        });

      }else{
        alert("请先输入正确的手机号码");
        return;
      }
  }
}


<?php $this->endBlock() ?>
<?php $this->registerJs($this->blocks['getsmscode'],\yii\web\View::POS_END); ?>
<!-- page body end-->
